﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using yq.ControllerBase;
using yq.Basis;

namespace yq.Controller
{
    /// <summary>
    /// 验证辅组类
    /// </summary>
    public class VerifyHelp
    {
        /// <summary>
        /// 初始化验证委托，验证委托注册
        /// </summary>
        public static void  Load()
        {
            //测试
            VerifyCaChe.Add(TestKey, VerifyFun.TestFun);

            //验证定时任务的执行时间配置是否合法
            VerifyCaChe.Add(TaskTimeKey,VerifyFun.TaskTimeFun);

            //文件权限判断
            VerifyCaChe.Add(FileCheckKey, VerifyFun.CheckFileFun);
            VerifyCaChe.Add(FileAdminKey, VerifyFun.FileAdminFun);
            VerifyCaChe.Add(FileWriteKey, VerifyFun.FileWriteFun);
            VerifyCaChe.Add(FileReadKey, VerifyFun.FileReadFun);
            VerifyCaChe.Add(FileMyKey, VerifyFun.FileMyFun);
        }


        public const string TestKey = "Test";

        /// <summary>
        /// 文件权限判断
        /// </summary>
        public const string FileCheckKey = "CheckFileKey";

        /// <summary>
        /// 文件权限判断
        /// </summary>
        public const string FileAdminKey = "FileAdminKey";

        /// <summary>
        /// 文件权限判断
        /// </summary>
        public const string FileWriteKey = "FileWriteKey";

        /// <summary>
        /// 文件权限判断
        /// </summary>
        public const string FileReadKey = "FileReadKey";

        /// <summary>
        /// 文件权限判断
        /// </summary>
        public const string FileMyKey = "FileMyKey";

        /// <summary>
        /// 验证定时任务的执行时间配置是否合法
        /// </summary>
        public const string TaskTimeKey = "TaskTime";


        /// <summary>
        /// 验证方法
        /// </summary>
        private class VerifyFun
        {
            public static Func<yq.Model.Logic.UserAccount, CurrentUser, bool> TestFun = (model, user) =>
            {
                return true;
            };

            /// <summary>
            /// 有读的权限可以访问
            /// </summary>
            public static Func<yq.Model.Logic.FileList, CurrentUser, bool> FileReadFun = (model, user) =>
            {
                if (model.UserId == user.UserId)
                {
                    return true;
                }

                return true;
            };

            /// <summary>
            /// 有写的权限可以访问
            /// </summary>
            public static Func<yq.Model.Logic.FileList, CurrentUser, bool> FileWriteFun = (model, user) =>
            {
                if (model.UserId == user.UserId)
                {
                    return true;
                }

                return true;
            };

            /// <summary>
            /// 有管理员权限可以访问
            /// </summary>
            public static Func<yq.Model.Logic.FileList, CurrentUser, bool> FileAdminFun = (model, user) =>
            {
                if (model.UserId == user.UserId)
                {
                    return true;
                }

                return true;
            };

            /// <summary>
            /// 私人的文件
            /// </summary>
            public static Func<yq.Model.Logic.FileList, CurrentUser, bool> FileMyFun = (model, user) =>
            {
                if (model.UserId == user.UserId)
                {
                    return true;
                }

                return false;
            };


            /// <summary>
            /// 签出判断
            /// </summary>
            public static Func<yq.Model.Logic.FileList, CurrentUser, bool> CheckFileFun = (model, user) =>
            {
                if (model.IsCheckOut == Enums.BooleanType.Yes && model.CheckUserId != user.UserId)
                {
                    //被签出了
                    return false;
                }
                return true;
            };


            //验证定时任务的执行时间配置是否合法
            public static Func<yq.Model.Logic.SysTask, CurrentUser, bool> TaskTimeFun = (model, user) =>
            {
                yq.Controller.Sys.TaskController ta = new Sys.TaskController();
                return ta.verify(model);
            };
        }
    }

  

}
